export default {
    state: {
        epmToken:"",//token值
        tabs:[],//已添加的tab页
        tabRoutes:[],//已添加的tab页-路由
        currentActiveMenu:"1",//当前激活的菜单
        excludeView:['BusinessWorkbench','ShopIndex','CardOpen','ShopOrderManager'],//路由缓存例外数组
        isMenuCollapse:true,
    },
    mutations: {
        /**
         * 将token放置到store中
         * @param state
         * @param token
         */
        setEpmToken(state,token){
            state.epmToken = token;
        },
        /**
         * 设置token最后一次更新时间
         * @param state
         * @param time
         */
        setTokenLastUpdateTime(state, time) {
            state.tokenLastUpdateTime = time;
        },
        /**
         * 添加tab页
         * @param state
         * @param tabObj
         */
        addTab(state,tabObj){
            let tabExist = false
            for(let i=0;i<state.tabs.length;i++){
                if(tabObj.router == state.tabs[i].router){
                    tabExist = true
                    break;
                }
            }
            if(!tabExist){
                state.tabs.push(tabObj);
            }
            sessionStorage.setItem("openedTabs",JSON.stringify(state.tabs));
        },
        removeAllTab(state) {
            state.tabs = [];
            sessionStorage.setItem("openedTabs", JSON.stringify(state.tabs));
        },
        updateTab(state,tabObj){
            let find = state.tabs.find(i => i.router === tabObj.router);
            find = tabObj;
        },
        /**
         * 删除tab页
         * @param state
         * @param tabName
         */
        removeTab(state,router){
            const _router = state.tabs.find(tab => tab.router === router);
            state.tabs = state.tabs.filter(tab => tab.router !== router);
            if(state.excludeView.indexOf(_router.name)===-1){
                state.excludeView.push(_router.name)
            }
            sessionStorage.setItem("openedTabs",JSON.stringify(state.tabs));
        },
        /**
         * 保存已打开的tab页到本地存储
         * @param state
         * @param arr
         */
        setTabs(state,arr){
            state.tabs = arr;
            sessionStorage.setItem("openedTabs",JSON.stringify(state.tabs));
        },
        /**
         * 设置当前选中的菜单
         * @param state
         * @param menuName
         */
        setCurrentActiveMenu(state,menuName){
            state.currentActiveMenu = menuName
            sessionStorage.setItem("currentActiveMenu",menuName);
        },
        /**
         * 添加路由缓存例外，关闭tab页时添加
         * @param state
         * @param viewName
         */
        addExcludeView(state,viewName){
            if(state.excludeView.indexOf(viewName)==-1){
                state.excludeView.push(viewName)
            }
        },

        /**
         * 删除路由缓存例外，打开tab页时添加
         * @param state
         * @param viewName
         */
        removeExcludeView(state,viewName){
            let index = state.excludeView.indexOf(viewName);
            if(index!=-1){
                state.excludeView.splice(index,1);
            }
        },

        //更改菜单状态
        changeMenuState(state,isCollapse){
            state.isMenuCollapse=isCollapse;
        },

    },
    actions:{

    },
    getters: {

    }
}